/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
// stop abstract class name check
package com.genia.toolbox.spring.transaction.bean;

import org.springframework.transaction.TransactionStatus;

import com.genia.toolbox.basics.exception.BundledException;

/**
 * Simple convenience class for TransactionCallback implementation. Allows for
 * implementing a doInTransaction version without result, i.e. without the need
 * for a return statement.
 * <p>
 * Inspired deeply from <code>TransactionCallbackWithoutResult</code> of
 * Spring Framework.
 * 
 * @see org.springframework.transaction.support.TransactionCallbackWithoutResult
 */
public abstract class TransactionCallbackWithoutResult // NOPMD
    implements TransactionCallback
{

  /**
   * Gets called by TransactionTemplate.execute within a transactional context.
   * Does not need to care about transactions itself, although it can retrieve
   * and influence the status of the current transaction via the given status
   * object, e.g. setting rollback-only.
   * <p>
   * Allows for returning a result object created within the transaction, i.e. a
   * domain object or a collection of domain objects. A RuntimeException thrown
   * by the callback is treated as application exception that enforces a
   * rollback. An exception gets propagated to the caller of the template.
   * <p>
   * Note when using JTA: JTA transactions only work with transactional JNDI
   * resources, so implementations need to use such resources if they want
   * transaction support.
   * 
   * @param status
   *          associated transaction status
   * @return <code>null</code>
   * @throws BundledException
   *           when an error occurred
   * @see com.genia.toolbox.persistence.transaction.TransactionCallback#doInTransaction(org.springframework.transaction.TransactionStatus)
   */
  public Object doInTransaction(final TransactionStatus status)
      throws BundledException
  {
    doInTransactionWithoutResult(status);
    return null;
  }



  /**
   * Gets called by TransactionTemplate.execute within a transactional context.
   * Does not need to care about transactions itself, although it can retrieve
   * and influence the status of the current transaction via the given status
   * object, e.g. setting rollback-only.
   * <p>
   * A RuntimeException thrown by the callback is treated as application
   * exception that enforces a rollback. An exception gets propagated to the
   * caller of the template.
   * <p>
   * Note when using JTA: JTA transactions only work with transactional JNDI
   * resources, so implementations need to use such resources if they want
   * transaction support.
   * 
   * @param status
   *          associated transaction status
   * @throws BundledException
   *           when an error occurred
   */
  protected abstract void doInTransactionWithoutResult(TransactionStatus status)
      throws BundledException;

}
// resume abstract class name check
